﻿using Google.ProtocolBuffers;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace LightingServer
{
    public class LightingDelete
    {
        public void Delete(DbConnection conn, Lighting lighting)
        {
            // 删除物理表
            DbCommand command = conn.CreateCommand();
            command.CommandText = "DELETE FROM physical WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Physical.Id
            });
            command.ExecuteNonQuery();

            // 删除光学参数
            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM optics WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Optics.Id
            });
            command.ExecuteNonQuery();

            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM electric WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Electric.Id
            });
            command.ExecuteNonQuery();

            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM adapterLighting WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.AdapterLighting.Id
            });
            command.ExecuteNonQuery();

            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM project WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Project.Id
            });
            command.ExecuteNonQuery();

            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM business WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Business.Id
            });
            command.ExecuteNonQuery();

            command = conn.CreateCommand();
            command.CommandText = "DELETE FROM picture WHERE id = @id ";
            command.Parameters.Add(new MySqlParameter()
            {
                ParameterName = "@id",
                DbType = DbType.String,
                Value = lighting.Picture.Id
            });
            command.ExecuteNonQuery();
        }
    }
}
